/*
  MinCC - Minimalist Compiler Collection
  Copyright (C) 2009 Scott Lawrence

  MinCC is free software: you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  MinCC is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  License for more details.

  You should have received a copy of the GNU General Public License
  along with mincc.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>

#include "cmdline.hpp"
#include "error.hpp"
#include "state.hpp"

START_OPTIONS()
    OPTION("--help",0,printHelp)
    OPTION("-h",0,printHelp)
    OPTION("--version",0,printVersion)
    OPTION("-o",1,setOutput)
    OPTION("--build",0,printBuildInfo)
    END_OPTIONS

void noargs() {
  printf("Usage: mincc [options] input files\n");
  printf("Try mincc --help for more information\n");
}

void execArg(int argc,char *argv[],int &start) {
  int i=-1;
  while(options[++i].args!=-1) {
      if(!strcmp(options[i].name,argv[start])) {
          if(argc-start-1<options[i].args) {
              IERRORT(3,options[i].name);
          }
          options[i].call(argv+start);
          start+=options[i].args;
          return;
      }
  }
  IERRORT(2,argv[start]);
}

int printHelp(char **args) {
    printf("help text\n");
    return 0;
}

int printVersion(char **args) {
    printf("%s\n",PACKAGE_STRING);
    printf("Copyright (c) 2009 Scott Lawrence\n");
    printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
    printf("This is free software; see the source for copying conditions.  There is NO\n");
    printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
    printf("Report bugs to %s\n",PACKAGE_BUGREPORT);
    return 0;
}

int printBuildInfo(char **args) {
    printf("%s Build Information\n",PACKAGE);
    return 0;
}

int setOutput(char **args) {
    return 0;
}
